package ArrayStudy;

import java.util.Arrays;
import java.util.Scanner;

public class ArrayGrow {
    public static void main(String[] args) {
        int[] a = {1, 2, 3};
        System.out.println("Arrays.toString(a) = " + Arrays.toString(a));

        while (true) {
            System.out.println("是否需要扩YorN");
            Scanner scanner = new Scanner(System.in);
            String ask = scanner.next();
            if (ask.equals("N")) {
                break;
            }
            System.out.println("请输入要添加的数据:");
            int num = scanner.nextInt();

            int[] b = new int[a.length + 1];
            for (int i = 0; i < a.length; i++) {
                b[i] = a[i];
            }
            a = b;
            a[a.length - 1] = num;
        }
        System.out.println("Arrays.toString(a) = " + Arrays.toString(a));
    }
}
